//修为配置
//label--展示名称
//attr -- 对应主属性
window._XW = {
    
    //装备 10条
    //attack defend mattack mdefend 1000 maxHp 10000
    'jian':{elv:0,label:'剑术',img:'剑术',attr:'attack',fsx:[{type:'attackPer',base:1},{type:'defendReduce',base:1}],
    skillbd:{}},
    'qiang':{elv:0,label:'枪棒',img:'枪棒',attr:'attack',fsx:[{type:'attackPer',base:1}],
    skillbd:{}},
    'dao':{elv:0,label:'刀法',img:'刀法',attr:'attack',fsx:[{type:'attackPer',base:1},{type:'stun',base:1}],
    skillbd:{}},
    'she':{elv:0,label:'射术',img:'射术',attr:'attack',fsx:[{type:'attackPer',base:1},{type:'hit',base:1}],
    skillbd:{}},
    'shan':{elv:0,label:'经略',img:'经略',attr:'mattack',fsx:[{type:'mattackPer',base:1}],
    skillbd:{}},

    'zhang':{elv:0,label:'杖法',img:'杖法',attr:'mdefend',fsx:[{type:'mattackPer',base:1},{type:'maxHpPer',base:1}],
    skillbd:{}},
     
    //mattackBack 2   	
    'zhong':{elv:0,label:'重甲',img:'重甲',attr:'defend',fsx:[{type:'defendPer',base:1},{type:'mattackBack',base:1}],
    skillbd:{}},
    //superAttack 2
    'pi':{elv:0,label:'皮甲',img:'皮甲',attr:'defend',fsx:[{type:'defendPer',base:1},{type:'superAttack',base:1}],
    skillbd:{}},
    //attackBack 2
    'bu':{elv:0,label:'布甲',img:'布甲',attr:'mdefend',fsx:[{type:'mdefendPer',base:1},{type:'attackBack',base:1}],
    skillbd:{beginMagic:1}},
    'bao':{elv:0,label:'御宝',img:'御宝',attr:'maxHp',fsx:[{type:'maxHpPer',base:1}],
    skillbd:{maxMagic:1}},	

    //功能 7条
    //gushang 1000
    'ys':{elv:1,label:'医术',img:'医术',attr:'mdefend',fsx:[{type:'maxHpPer',base:1}],
    skillbd:{poison:1}},
    //defendReduce 1
    'bc':{elv:1,label:'辩才',img:'辩才',attr:'mattack',fsx:[{type:'defendReduce',base:1}],
    skillbd:{}},
    //mdefendReduce 1
    'zhous':{elv:1,label:'咒术',img:'咒术',attr:'mattack',fsx:[{type:'mdefendReduce',base:1}],
    skillbd:{}},	
    //stunMiss 1
    'bh':{elv:1,label:'变化',img:'变化',attr:'maxHp',fsx:[{type:'stunMiss',base:1}],
    skillbd:{}},
    //miss 2
    'ds':{elv:1,label:'盗术',img:'偷窃',attr:'mdefend',fsx:[{type:'miss',base:1}],
    skillbd:{equipDrop:1,skillDrop:1}},//摸金校尉--道具掉落 
    //aqDamage 5
    'aq':{elv:1,label:'暗器',img:'暗器',attr:'defend',fsx:[{type:'aqDamage',base:1}],
    skillbd:{aqDistance:1,aqScope:1}},//暗器命中 暗器伤害 暗器射程  暗器范围 
    //damagePlus 2
    'wux':{elv:1,label:'武学',img:'武学',attr:'attack',fsx:[{type:'superDamagePlus',base:1}],
    skillbd:{lianji:1,xiezhan:1,fanji:1}},//连击 分身

    //特殊	7条
    //gedang 2
    'tp':{elv:2,label:'体魄',img:'体魄',attr:'maxHp',fsx:[{type:'gedang',base:1}],
    skillbd:{}},//血量
    //damageReduce 2
    'kj':{elv:2,label:'空间',img:'空间',attr:'defend',fsx:[{type:'damageReduce',base:1}],
    skillbd:{fly:1,move:1,againMove:1}},
    //speed 1
    'sf':{elv:2,label:'身法',img:'身法',attr:'attack',fsx:[{type:'speed',base:1}],
    skillbd:{speed:1,anqimianyi:1}},//新增	
    //superDamagePlus 3
    'bq':{elv:2,label:'霸气',img:'霸气',attr:'maxHp',fsx:[{type:'damagePlus',base:1}],
    skillbd:{weifeng:1}},//新增	
    //stun 1
    'nl':{elv:2,label:'念力',img:'念力',attr:'mattack',fsx:[{type:'stun',base:1}],
    skillbd:{poge:1}},//新增	
    //death 0.5
    'bl':{elv:2,label:'臂力',img:'臂力',attr:'maxHp',fsx:[{type:'death',base:1}],
    skillbd:{distance:1}}, 
    //hit 2
    'xx':{elv:2,label:'修心',img:'修心',attr:'mdefend',fsx:[{type:'hit',base:2}],
    skillbd:{aqPer:1,magicPer:1}},

    //种族 12条
    // (仙 精神+血量)(魔 攻击+血量)(人 魔防+物防)
    //attackPer mattackPer defendPer mdefendPer maxHpPer 5 
    'xs':{elv:3,label:'仙术',img:'仙术',attr:'mattack',fsx:[{type:'mattackPer',base:1}],
    skillbd:{scope:1,nodeath:1}},
    'sq':{elv:3,label:'神祇',img:'神祇',attr:'maxHp',fsx:[{type:'maxHpPer',base:1}],
    skillbd:{strongEnergy:1,shendun:1}},//神兽技能 
    'fx':{elv:3,label:'法相',img:'法相',attr:'defend',fsx:[{type:'mattackPer',base:1}],
    skillbd:{ironwall:1,clearBody:1}},//新增

    'yaos':{elv:3,label:'妖术',img:'妖',attr:'attack',fsx:[{type:'attackPer',base:1}],
    skillbd:{lianjiSkill:1,statusBody:1}},
    'hs':{elv:3,label:'魂术',img:'魂术',attr:'mattack', fsx:[{type:'attackPer',base:1}],
    skillbd:{magicCloth:1,yuanhun:1}},//新增	
    'yus':{elv:3,label:'驭兽',img:'驭兽',attr:'defend',fsx:[{type:'maxHpPer',base:1}],
    skillbd:{fanzhi:1,beActive:1}},//新增	
    
    'bf':{elv:3,label:'兵法',img:'兵法',attr:'defend',fsx:[{type:'defendPer',base:1}],
    skillbd:{hardwork:1,shareExp:1}},
    'jg':{elv:3,label:'机关',img:'机械',attr:'mdefend',fsx:[{type:'mdefendPer',base:1}],
    skillbd:{goldCloth:1}},//人族机关
    'ny':{elv:3,label:'能源',img:'能源',attr:'maxHp',fsx:[{type:'maxHpPer',base:1}],
    skillbd:{beginEnergy:1,missEnergy:1,hitEnergy:1}},//初始能量 蓄势 集气
    
    'kh':{elv:3,label:'狂化',img:'狂化',attr:'attack',fsx:[{type:'maxHpPer',base:1}],
    skillbd:{sblood:1,blood:1}},//新增	
    'fj':{elv:3,label:'佛经',img:'佛经',attr:'mdefend',fsx:[{type:'maxHpPer',base:1}],
    skillbd:{clearHeart:1,eye:1}},//新增
    'zs':{elv:3,label:'再生',img:'再生',attr:'maxHp',fsx:[{type:'maxHpPer',base:1}],
    skillbd:{hpRecovery:1,MagicRecovery:1}},//新增
     
    //五行 5条
    //goldPlus woodPlus firePlus soliPlus waterPlus
    //woodReduce soliReduce fireReduce goldReduce waterReduce
    'jin':{elv:4,label:'锐金',img:'锐金',attr:'mattack',fsx:[{type:'goldPlus',base:1},{type:'woodReduce',base:1}],
    skillbd:{pandeng:1}},
    'mu':{elv:4,label:'巨木',img:'巨木',attr:'maxHp',fsx:[{type:'woodPlus',base:1},{type:'soliReduce',base:1}],
    skillbd:{youji:1}},
    'shui':{elv:4,label:'洪水',img:'洪水',attr:'mdefend',fsx:[{type:'waterPlus',base:1},{type:'fireReduce',base:1}],
    skillbd:{caoduo:1}},
    'huo':{elv:4,label:'烈火',img:'烈火',attr:'attack',fsx:[{type:'firePlus',base:1},{type:'goldReduce',base:1}],
    skillbd:{bihuo:1}},
    'tu':{elv:4,label:'厚土',img:'厚土',attr:'defend',fsx:[{type:'soliPlus',base:1},{type:'waterReduce',base:1}],
    skillbd:{bidu:1}},
};


//修为成长范围
window._XWLEVEL = {
    'D':[1.3,2.5],//500 1.2
    'C':[2.5,3.7],//300 1.2
    'B':[3.7,4.9],//200 1.2
    'A':[4.9,6.1],//150 1.2
    'S':[8.1,10.1],//100 2
    'SS':[12.1,15.1],//80 3
}


window.XWH = {

    _ALLXW:null,

    _EARR:null,

    //根据孔位获取随机修为
    getRandomXwByElv:function(elv){

        if(!XWH._EARR){
            XWH._EARR=[[],[],[],[],[]];
            for(var key in _XW){
                var index = _XW[key].elv;
                XWH._EARR[index].push(key);
            }
        }
        return _CU.randomObj(XWH._EARR[elv]);
    },

    getRandomXw:function(){

        if(!XWH._ALLXW){
            XWH._ALLXW=[];
            for(var xw in window._XW){
                XWH._ALLXW.push(xw);
            }
        }

        return XWH._ALLXW[Math.floor(Math.random()*XWH._ALLXW.length)];

    },

    createXwPart:function(){

        var msg  = "";

        for(var xw in _XW){

            var name = _XW[xw].label;

            var message = ",相关锻造副属性:";
            var xwfsxconfig = _XW[xw].fsx;
            console.log(xwfsxconfig);
            if(xwfsxconfig&&xwfsxconfig.length>0){
                for(var i=0;i<xwfsxconfig.length;i++){
                    var fsx=xwfsxconfig[i].type;
                    
                    message+=_DICT[fsx]+" ";
                }
            }

            msg += "'"+name+"符文':{skilltype:'bosspart',img:'"+name+"',xw:'"+xw+"',lv:1000,qua:'SS',des:'镶嵌至装备获得"+name+"修为"+message+"',forbidden:1},\n";

        }

        console.log(msg);
    },

    testXwbook:function(){

        var fsxmap = {};

        for(var xw in _XW){
            for(var i=0;i<_XW[xw].fsx.length;i++){
                fsxmap[_XW[xw].fsx[i].type]=1;
                if(!_DICT[_XW[xw].fsx[i].type]){
                    console.log(_XW[xw].label+" 锻造属性("+_XW[xw].fsx[i].type+")不存在");
                }
            }
        }

        console.log("以下副属性不存在锻造:");
        for(var key in _DICT){
            if(!fsxmap[key]){
                console.log(_DICT[key]+" "+key);
            }
        }
    },


    getXwcz:function(obj,role){

        var result = "";

        if(!role.xwlevel){

            for(var key in obj){

                var xwname = _XW[key].label;
                if(result==""){
                    result = xwname+":"+obj[key]+"("+role.xw[key]+")";
                }else{
                    result+="\n"+xwname+":"+obj[key]+"("+role.xw[key]+")";
                }

            }

        }else{

            for(var key in role.xwlevel){

                var xwname = _XW[key].label;
                if(result==""){
                    result = xwname+":"+role.xwlevel[key]+"("+role.xw[key]+")";
                }else{
                    result+="\n"+xwname+":"+role.xwlevel[key]+"("+role.xw[key]+")";
                }

            }

        }


        return result;
    },

    canGetXw:function(role,xw){

        if(role.xw){

            if(role.xw[xw]){
                _TIPS.showMessage('无法重复开启同一种修为',0);
                return false;
            }

            var xwnmb = 0;

            for(var key in role.xw){

                xwnmb++;

            }

            if(xwnmb>=8){

                _TIPS.showMessage('同一角色最多习得8种修为',0);
                return false;

            }
        }

        return true;

    },

    getStrOfXwObj:function(xwobj){

        if(xwobj){
            var result = "修为:";
            var hasattr = false;
            for(var key in xwobj){
                if(_XW[key])
                result+=_XW[key].label+xwobj[key]+" ";
                hasattr = true;
            }

            if(hasattr){
                return result;
            }
        }

        return "";

    },


    isXwEnough2:function(target,source){

        if(!target)
            return true;

        if(!source)
            return false;

        for(var key in target){

            if(!source[key]
                ||source[key]<target[key]
            ){
                return false;
            }

        }

        return true;

    },

    isXwNmbEnough:function(target,source){

        if(!target)
            return true;

        if(!source)
            return false;

        for(var key in target){

            if(!source[key]
                //||source[key]<target[key]
            ){
                return false;
            }

        }

        return true;

    },


    //判断修为是否匹配 target--目标  source--本身 格式{xw:{}}
    isXwEnough:function(target,source){

        if(
            !target
            ||!target.xw
        ){
            return true;
        }

        if(
            source
            &&source.xw
        ){

            for(var key in target.xw){

                if(target.xw[key]>0){
                    if(!source.xw[key]
                        ||source.xw[key]<target.xw[key]
                    ){
                        return false;
                    }
                }
            }

            return true;

        }

        return false;

    },

    showXwDes:function(xw){

        var xwconfig = _XWDS[xw];
        var xwattr = null;

        if(!xwconfig){
            for(var key in _XWDS){
                if(_XWDS[key].label==xw){
                    xwconfig = _XWDS[key];
                    xwattr=_XW[key].attr;
                    xw=key;
                }
            }
        }else{
            xwattr=_XW[xw].attr;
        }

        if(!xwconfig){
            return "未知:"+xw;
        }

       //console.log(xwconfig);

        var message = xwconfig.label+":\n";
        message+="此修为每增长1点增加1/1000的"+_DICT[xwattr];

        var xwfsxconfig = _CU.objToArr(xwconfig.dz);
        if(xwfsxconfig&&xwfsxconfig.length>0){
            message+="\n相关锻造副属性:";
            for(var i=0;i<xwfsxconfig.length;i++){
                var fsx=xwfsxconfig[i];
                message+=_DICT[fsx]+" ";
            }
        }

        var xwbdconfig = _CU.objToArr(xwconfig.skillbd);
        if(xwbdconfig&&xwbdconfig.length>0){
            message+="\n相关被动副属性:";
            for(var i=0;i<xwbdconfig.length;i++){
                var fsx=xwbdconfig[i];
                message+=_DICT[fsx]+" ";
            }
        }

        var xwstatusconfig = _CU.objToArr(xwconfig.status);
        if(xwstatusconfig&&xwstatusconfig.length>0){
            message+="\n相关状态:";
            for(var i=0;i<xwstatusconfig.length;i++){
                var fsx=xwstatusconfig[i];
                message+=_STATUSCONFCHESS[fsx].name+" ";
            }
        }

        var xwskilltype = _CU.objToArr(xwconfig.skilltype);
        if(xwskilltype&&xwskilltype.length>0){
            message+="\n相关主动技能:";
            for(var i=0;i<xwskilltype.length;i++){
                var fsx=xwskilltype[i];
                message+=fsx+" ";
            }
        }


        message+="\n符文出现地点:"+_FWJPHELPER.getFwPlace(xw);

        return message;

    },

    //修为配置检测 查看独占
    testZzXw:function(){

        var raceMap = {};
        var raceXwMap = {};
        var loseXw = [];
        var loseFsx = [];
        var xwmb=0;
        var fsxnmb=0;

        //根据npc修为配置获取 种族包含修为
        for(var key in _NPC){

            var race = _NPC[key].race;
            if(!raceMap[race]){
                raceMap[race]={xw:[],fsx:[],xwmap:{},fsxmap:{},noxw:[],onlyxw:[],nofsx:[],onlyfsx:[]};
            }

            for(var npcxw in _NPC[key].npcxw){
                if(!raceMap[race].xwmap[npcxw]){
                    raceMap[race].xwmap[npcxw]=1;
                    raceMap[race].xw.push(npcxw);

                    if(_XW[npcxw].fsx){
                        for(var i=0;i<_XW[npcxw].fsx.length;i++){
                            var fsx = _XW[npcxw].fsx[i].type;
                            if(!raceMap[race].fsxmap[fsx]){
                                raceMap[race].fsxmap[fsx]=1;
                                raceMap[race].fsx.push(fsx);
                            }
                        }
                    }
                }
            }

        }

        //根据种族包含修为和被动获取种族包含副属性
        for(var key in raceMap){
            for(var s in _SKILLBD){
                if(XWH.isXwNmbEnough(_SKILLBD[s].xw,raceMap[key].xwmap)){
                    for(var fsx in _SKILLBD[s].attr){
                        if(!raceMap[key].fsxmap[fsx]){
                            raceMap[key].fsxmap[fsx]=1;
                            raceMap[key].fsx.push(fsx);
                        }
                    }
                }
            }
        }


        for(var key in _XW){
            var xwname = _XW[key].label;
            for(var r in raceMap){
                if(!raceMap[r].xwmap[key]){
                    raceMap[r].noxw.push(xwname);
                }
            }

            if(
                raceMap['yao'].xwmap[key]
                &&!raceMap['ren'].xwmap[key]
                &&!raceMap['xian'].xwmap[key]
            ){
                raceMap['yao'].onlyxw.push(xwname);
            }

            if(
                raceMap['ren'].xwmap[key]
                &&!raceMap['yao'].xwmap[key]
                &&!raceMap['xian'].xwmap[key]
            ){
                raceMap['ren'].onlyxw.push(xwname);
            }

            if(
                raceMap['xian'].xwmap[key]
                &&!raceMap['ren'].xwmap[key]
                &&!raceMap['yao'].xwmap[key]
            ){
                raceMap['xian'].onlyxw.push(xwname);
            }

            if(
                !raceMap['yao'].xwmap[key]
                &&!raceMap['ren'].xwmap[key]
                &&!raceMap['xian'].xwmap[key]
            ){
                loseXw.push(xwname);
            }

            xwmb++;
        }

        for(var key in _DICT){
            var fsxname = _DICT[key];
            for(var r in raceMap){
                if(!raceMap[r].fsxmap[key]){
                    raceMap[r].nofsx.push(fsxname);
                }
            }

            if(
                raceMap['xian'].fsxmap[key]
                &&!raceMap['ren'].fsxmap[key]
                &&!raceMap['yao'].fsxmap[key]
            ){
                raceMap['xian'].onlyfsx.push(fsxname);
            }

            if(
                raceMap['yao'].fsxmap[key]
                &&!raceMap['ren'].fsxmap[key]
                &&!raceMap['xian'].fsxmap[key]
            ){
                raceMap['yao'].onlyfsx.push(fsxname);
            }

            if(
                raceMap['ren'].fsxmap[key]
                &&!raceMap['xian'].fsxmap[key]
                &&!raceMap['yao'].fsxmap[key]
            ){
                raceMap['ren'].onlyfsx.push(fsxname);
            }

            if(
                !raceMap['yao'].fsxmap[key]
                &&!raceMap['ren'].fsxmap[key]
                &&!raceMap['xian'].fsxmap[key]
            ){
                loseFsx.push(fsxname);
            }

            fsxnmb++;
        }

        for(var r in raceMap){
            if(r=="xian"||r=="yao"||r=="ren"){
                for(var i=0;i<raceMap[r].onlyxw.length;i++){
                    raceXwMap[raceMap[r].onlyxw[i]]=1;
                }

                for(var i=0;i<raceMap[r].noxw.length;i++){
                    raceXwMap[raceMap[r].noxw[i]]=1;
                }
            }
        }
       

        console.log('###################人族');
        console.log('独占修为',raceMap['ren'].onlyxw);
        console.log('缺失修为',raceMap['ren'].noxw);
        console.log('独占副属性',raceMap['ren'].onlyfsx);
        console.log('缺失副属性',raceMap['ren'].nofsx);

        console.log('###################妖族');
        console.log('独占修为',raceMap['yao'].onlyxw);
        console.log('缺失修为',raceMap['yao'].noxw);
        console.log('独占副属性',raceMap['yao'].onlyfsx);
        console.log('缺失副属性',raceMap['yao'].nofsx);

        console.log('###################仙族');
        console.log('独占修为',raceMap['xian'].onlyxw);
        console.log('缺失修为',raceMap['xian'].noxw);
        console.log('独占副属性',raceMap['xian'].onlyfsx);
        console.log('缺失副属性',raceMap['xian'].nofsx);

        console.log('###################种族修为',raceXwMap);
        console.log("修为总数",xwmb);
        console.log("副属性总数",fsxnmb);
        console.log("缺失修为",loseXw);
        console.log("缺失副属性",loseFsx);
    },




    //打印修为解锁顺序
    testXwSeq:function(zz){

        var xwmap = {};
        var nmb = 0;
        for(var key in _NPCMAP){
            var npcarr = _NPCMAP[key].npc;
            for(var i=0;i<npcarr.length;i++){
                var npcname = npcarr[i].npc;
                var npcconfig = _NPC[npcname];
                if((npcconfig.race == zz||zz==null)&&(!npcconfig.isboss)){
                    var npcxw = npcconfig.npcxw;
                    for(var xw in npcxw){
                        if(!xwmap[xw]){
                            xwmap[xw]=1;
                            console.log(_NPCMAP[key].lv,_XW[xw].label);
                            nmb++;
                        }
                    }
                }
            }
        }

        console.log(nmb);
        console.log("###################");
        for(var key in _XW){
            if(!xwmap[key]){
                console.log(_XW[key].label+"("+key+")"+"缺失");
            }
        }

        
    }

}